package bbb;

public class Award {

	public static Integer AW_LEVEL_NONE = -1;
	public static Integer AW_LEVEL_1 = 1;
	public static Integer AW_LEVEL_2 = 2;
	public static Integer AW_LEVEL_3 = 3;
	public static Integer AW_LEVEL_4 = 4;
	public static Integer AW_LEVEL_5 = 5;
	public static Integer AW_LEVEL_6 = 6;
	
	public static int TOTAL_COUNT = 17721088;
	public static double RATE_LEVEL_1 = 1.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_2 = 15.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_3 = 162.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_4 = 7695.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_5 = 137475.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_6 = 1043640.0 / TOTAL_COUNT;
	public static double RATE_LEVEL_NONE = 16532100.0 / TOTAL_COUNT;
	
	public static Integer RMB_LEVEL_1 = 7500000;
	public static Integer RMB_LEVEL_2 = 300000;
	public static Integer RMB_LEVEL_3 = 3000;
	public static Integer RMB_LEVEL_4 = 200;
	public static Integer RMB_LEVEL_5 = 10;
	public static Integer RMB_LEVEL_6 = 5;
	public static Integer RMB_LEVEL_NONE = 0;

	public static Integer matchAward(BallInfo curBall, BallInfo awardBall) {
		boolean bm = blueMatch(curBall, awardBall);
		int rm = redMatch(curBall, awardBall);
		if(bm){
			if(rm<3){
				return AW_LEVEL_6;
			}else if(rm == 3){
				return AW_LEVEL_5;
			}else if(rm == 4){
				return AW_LEVEL_4;
			}else if(rm == 5){
				return AW_LEVEL_3;
			}else if(rm == 6){
				return AW_LEVEL_1;
			}
		}else{
			if(rm == 4){
				return AW_LEVEL_5;
			}else if(rm == 5){
				return AW_LEVEL_4;
			}else if(rm == 6){
				return AW_LEVEL_2;
			}
		}
		return AW_LEVEL_NONE;
	}

	public static boolean blueMatch(BallInfo b1, BallInfo b2) {
		if (b1.getBlue() == b2.getBlue()) {
			return true;
		}
		return false;
	}

	public static int redMatch(BallInfo b1, BallInfo b2) {
		int count = 0;
		if(oneRedMatch(b1.getRed1(), b2)){
			count++;
		}
		if(oneRedMatch(b1.getRed2(), b2)){
			count++;
		}
		if(oneRedMatch(b1.getRed3(), b2)){
			count++;
		}
		if(oneRedMatch(b1.getRed4(), b2)){
			count++;
		}
		if(oneRedMatch(b1.getRed5(), b2)){
			count++;
		}
		if(oneRedMatch(b1.getRed6(), b2)){
			count++;
		}
		return count;
	}
	
	private static boolean oneRedMatch(Integer a ,BallInfo ball){
		if(a!=null && ball!=null){
			if(a.equals(ball.getRed1())
					|| a.equals(ball.getRed2())
					|| a.equals(ball.getRed3())
					|| a.equals(ball.getRed4())
					|| a.equals(ball.getRed5())
					|| a.equals(ball.getRed6())
					){
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		BallInfo b1 = ParserUtils.parse("2014-01-28 2014012 01 08 11 19 21 24 08");
		BallInfo b2 = ParserUtils.parse("2014-01-28 2014012 02 07 11 19 21 24 04");
		System.out.println(matchAward(b1, b2));
	}
}
